<template>
    <div class="dialog-box">
        <el-dialog class="dialog" v-model="visible" title="选择发放券" top="80px" draggable overflow
            :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
            <el-divider class="my-divider" />
            <el-form class="search-form" inline :model="searchForm">
                <div>
                    <el-form-item class="search-form-item" label="券名称:">
                        <el-input v-model="searchForm.ticketName" placeholder="券名称" clearable />
                    </el-form-item>
                    <el-form-item class="search-form-item" label="券类型:">
                        <el-select v-model="searchForm.typeCode" filterable clearable>
                            <el-option v-for="item in ticketType_options" :key="item.code" :value="item.code"
                                :label="item.name" />
                        </el-select>
                    </el-form-item>

                    <el-form-item class="action-btn-box">
                        <el-button type="primary" @click="handleSearch">查询</el-button>
                        <el-button class="reset-btn" @click="handleReset">清空筛选</el-button>
                    </el-form-item>
                </div>
            </el-form>
            <div class="table-box">
                <el-table :data="tableData" v-loading="loading" highlight-current-row
                    @current-change="handleCurrentChange_table">
                    <el-table-column prop="TicketName" label="券名称" />
                    <el-table-column prop="TicketAmt" label="面值" />
                    <el-table-column prop="TypeCodeName" label="券类型" />
                    <el-table-column prop="OrgName" label="使用门店" />
                    <!-- <el-table-column prop="" label="操作" min-width="16%" fixed="right">
                        <template #default="scope">
                            <el-button class="action-btn" @click="handleDetail"> 回复</el-button>
                        </template>
                    </el-table-column> -->
                </el-table>
            </div>
            <!-- <div class="pagination-box">
        <el-pagination background layout="prev, pager, next,sizes, jumper, total" :total="total" :v-model="currentPage"
            @size-change="handleSizeChange" @current-change="handleCurrentChange" style="margin-top:10px" />
    </div> -->
            <div class="orderRecords-container-footer">
                <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page.sync="currentPage" :page-size="pageSize" layout="total, prev, pager, next,sizes, jumper"
                    :total="total">
                </el-pagination>
                <!-- <button class="footer-button">确定</button> -->
            </div>


            <div class="footer-box">
                <el-button class="cancel" @click="handleCancel">取消</el-button>
                <el-button class="submit" @click="handleSubmit">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>
  
<script setup>
import Api from '@/api'
const props = defineProps({
    visible: {
        type: Boolean,
        required: false,
    },
    form: {
        type: Object,
        required: false,
    }
})
const visible = toRef(props, 'visible')
const form = toRef(props, 'form')

// 获取券类型OPTIONS
let ticketType_options = ref({ re: [] })
const get_ticketType_options = (code) => {
    ticketType_options.value = [
        { code: "1", name: "优惠券" },
        { code: "2", name: "折扣券" },
        { code: "3", name: "兑换券" },
        { code: "4", name: "排队券" },
    ]
}
get_ticketType_options()

let loading = ref(false)
let searchForm = ref({})
// 搜索
const handleSearch = (params) => {
    currentPage.value = 1;
    getTableData();
}
// 重置
const handleReset = (params) => {
    searchForm.value = {}
    handleSearch()
}
// 查询表格数据
let tableData = ref([{}])
let currentPage = ref(1)
let pageSize = ref(10)
let total = ref(0)
const handleSizeChange = (val) => {
    pageSize.value = val
    getTableData()
}
const handleCurrentChange = (val) => {
    currentPage.value = val
    getTableData()
}
const getTableData = (user) => {
    let query = {
        ...searchForm.value,
        pageIndex: currentPage.value,
        pageSize: pageSize.value
    }
    if (query.operDate && query.operDate.length > 1) {
        query.operDateStart = query.operDate[0]
        query.operDateEnd = query.operDate[1]
    }
    console.log('查询前的query :>> ', query,);
    loading.value = true
    // return
    Api.Common.PcObjProcess.Do({ "functionName": "GetOrgTicketList", "orgCode": "0004", "contentData": query }).then(res => {
        console.log('查询订单table res :>> ', res,);
        loading.value = false
        tableData.value = res.data
        total.value = res.totalCount
    })
}
getTableData()

// 点击单选事件
const handleCurrentChange_table = (val) => {
    form.value.currentTicket = val
}


// 取消
const emit = defineEmits(['emitCancel', 'emitSubmit'])
const handleCancel = (params) => {
    emit('emitCancel', 'cancel')
}
// 确认
const handleSubmit = (params) => {
    if (!form.value.currentTicket) return ElNotification({
        title: '提示',
        message: '请选择发放的券',
        type: 'warning',
    })
    console.log('form.value,currentTicket :>> ', form.value.currentTicket);
    // console.log(form.re)
    emit('emitSubmit', 'emitSubmit')
}


</script>
  
<style  lang="scss" scoped>
.dialog-box {
    ::v-deep {
        .el-dialog {
            width: 1000px;
            border-radius: 16px;
        }

        .el-form-item__label {
            // line-height: 40px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 16px;
            color: #212121;
        }

        .el-date-editor {
            // width: 350px;

        }

        .el-input {
            // width: 230px;
        }

        .el-input__wrapper {
            // height: 40px;
            background: #FAFAFA;
            border-radius: 8px;
        }

        .el-select__wrapper {
            // width: 160px;
            // height: 40px;
            background: #FAFAFA;
            border-radius: 8px;
        }
    }
}

.my-divider {
    margin: 0;
}

.footer-box {
    margin-top: 60px;
    display: flex;
    justify-content: center;

    .cancel {
        width: 160px;
        height: 60px;
        background: #FFFFFF;
        border-radius: 8px;
        border: 1px solid #FF6A00;
        font-size: 24px;
        color: #FF6A00;
    }

    .submit {
        width: 160px;
        height: 60px;
        background: #FF6A00;
        border-radius: 8px;
        font-size: 24px;
        color: #FFFFFF;
        margin-left: 30px;
    }
}

.search-form {
    // width: 1520px;
    background: #FFFFFF;
    border-radius: 8px;
    padding: 20px 10px 0 40px;
    margin-bottom: 20px;

    // display: flex;
    .search-form-item {
        ::v-deep {
            .el-form-item__label {
                line-height: 40px;
            }

            .el-date-editor {
                width: 350px;

            }

            .el-input {
                width: 220px;
            }

            .el-input__wrapper {
                height: 40px;
                background: #FAFAFA;
                border-radius: 8px;
            }

            .el-select__wrapper {
                width: 220px;
                height: 40px;
                background: #FAFAFA;
                border-radius: 8px;
            }
        }
    }

    .range-item {
        .el-input {
            width: 130px;
        }
    }

    .action-btn-box {
        float: right;

        button {
            width: 100px;
            height: 40px;
            line-height: 40px;
            background: #FFE566;
            border-radius: 8px;
            border: 0;
            font-size: 16px;
            color: #212121;
        }

        .reset-btn {
            background: #E6E6E6;
            color: #666666;
        }
    }
}

.table-box {
    padding: 20px 40px;
    background: #FFFFFF;
    border-radius: 8px;
    // width: 1520px;

    .total-box {
        display: flex;
        justify-content: space-between;
        margin-bottom: 20px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 20px;
        color: #212121;
    }

    ::v-deep {
        .el-table__inner-wrapper::before {
            height: 0px;
        }

        .el-table th {
            font-size: 13px;
            font-weight: 700;
        }

        .el-table .el-table__header th,
        .el-table .el-table__header tr,
        .el-table .el-table__header td {
            height: 48px;
            background: #F9F9F9;
        }
    }

    .action-btn {
        width: 66px;
        height: 28px;
        border-radius: 4px;
        border: 1px solid #FF6A00;
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 14px;
        color: #FF6A00;
    }
}

.pagination-box {
    margin-top: 20px;

    ::v-deep {
        .number {
            background: #E6E6E6 !important;
            border-radius: 8px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #666666;
        }

        .number:hover {
            color: #FF6A00;
        }

        .is-active {
            background-color: #FF6A00 !important;
            border-radius: 8px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #FFFFFF;
        }

    }
}
</style>
  